package ch.fhnw.qualiscan.api;

import java.util.List;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;

import ch.fhnw.qualiscan.api.output.SurveyOutput;
import ch.fhnw.qualiscan.api.output.SurveysOutput;
import ch.fhnw.qualiscan.application.models.ApiModel;
import ch.fhnw.qualiscan.core.db.pojos.Survey;

@Path("/surveys")
public class SurveyAPI {
	
	@Context
    protected UriInfo uriInfo;

    @Context
    protected Request request;
	
    ApiModel model;
    Response response = null;
    
    public SurveyAPI() {
		model = new ApiModel();
	}
    
    @GET
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    public Response getSurveys() {
    	List<Survey> surveys = model.getSurveyList();
    	SurveysOutput sO = new SurveysOutput(surveys);
    	
		response = Response.ok(sO).build();
        return response;
    }
    
    @GET
    @Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
    @Path("{id}")
    public Response getSurvey(@PathParam("id") int id) {
    	Survey survey = model.getSurvey(id);
    	SurveyOutput sO = new SurveyOutput(survey);
    	response = Response.ok(sO).build();
        return response;
    }
	
}
